package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 对象流是高级流，作用是进行对象的序列化( 将Java 对象的状态转换为字节序列)与反序化
 * 序列化如下
 */
public class OosDemo {
    public static void main(String[] args) throws IOException {
        /*String name = "张三";
        int age = 20;
        String gender = "男";
        String[] otherInfo = {"汉族","党员","技术好"};
        Person person = new Person(name,age,gender,otherInfo);
        FileOutputStream fos = new FileOutputStream("./person.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(person);
        oos.close();
        System.out.println("写入文件完毕");*/


        String name = "李华";
        int age = 23;
        String gender = "女";

        String[] otherInfo = {"汉族","团员","素质高"};
        Person person = new Person(name,age,gender,otherInfo);
        FileOutputStream fos = new FileOutputStream("./person.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        //Serializable相当于只是个标记，标记了就说明这个类对象是可序列化的。
        // 如果没有实现这个接口，得到这个标记，那么在进行序列化的时候会抛出异常。
        oos.writeObject(person);
        oos.close();
        System.out.println("写入文件完毕");
    }
}
